package servlet.manage.company;

import model.CompanyModel;
import net.sf.json.JSONArray;
import service.ICompanyService;
import service.impl.CompanyServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/CompanyAdd")
public class CompanyAddServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("UTF-8");//请求编码格式为utf-8
        resp.setCharacterEncoding("UTF-8");//响应编码格式为utf-8
        resp.setContentType("text/json;charset=utf-8");//解决传值乱码

        //拿到数据
//        String logo=req.getParameter("logo");
//        String phone=req.getParameter("phone");
//        String ad=req.getParameter("ad");
//        String html=req.getParameter("html");
//        String email=req.getParameter("email");
//        String linePhone=req.getParameter("linePhone");
//        String edition=req.getParameter("edition");

        //封装数据
        CompanyModel model=new CompanyModel();
        model.setLogo(req.getParameter("logo"));
        model.setPhone(req.getParameter("phone"));
        model.setAd(req.getParameter("ad"));
        model.setHtml(req.getParameter("html"));
        model.setEmail(req.getParameter("email"));
        model.setLinePhone(req.getParameter("linePhone"));
        model.setEdition(req.getParameter("edition"));

        //调用服务逻辑层
        ICompanyService service=new CompanyServiceImpl();
        int num=service.add(model);

        resp.getWriter().println(num);

    }
}
